package com.smallframework.mvc;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * Created by tan on 2017/7/4.
 */
public class ContextLoadListener implements ServletContextListener {
	public static final String CONFIG_LOCATION_PARAM = "contextConfigLocation";

	@Override
	public void contextInitialized(ServletContextEvent sce) {
		ClassHelper classHelper = new ClassHelper();
		classHelper.setBasePacakage("com.smallframework.demo");

		IOCContainer iocContainer = new IOCContainer();
		iocContainer.setClassHelper(classHelper);

		try {
			iocContainer.createInstanceAndInjectField();
			sce.getServletContext().setAttribute("iocContainer", iocContainer);

			RequestHandlerContainer requestHandlerContainer = new RequestHandlerContainer(iocContainer);
			requestHandlerContainer.init();
			sce.getServletContext().setAttribute("requestHandlerContainer", requestHandlerContainer);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public void contextDestroyed(ServletContextEvent sce) {

	}
}
